<?php
	class R_jumlah_pns_mod extends Model{
		function R_jumlah_pns_mod(){
			parent::Model(); $this->load->model('Datum_model');  
		}

		function list_jumlah_header($print_mode=false) {
            if ($print_mode==false) { 
            $s = "<table id=\"myTable\" class=\"tbl\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" >".
                 "<thead><tr><th rowspan=\"2\">No</th><th rowspan=\"2\">Unit Kerja</th><th rowspan=\"2\">Jumlah</th>".
                 "<th colspan=\"2\">Jenis Kelamin</th>".
                 "<th colspan=\"7\">Agama</th>".
                 "<th colspan=\"4\">Golongan Darah</th></tr>".
                 "<tr> ".
                 "<th>Lk</th><th>Pr</th>".
                 "<th>Islam</th><th>Protestan</th><th>Katolik</th><th>Hindu</th><th>Budha</th><th>Konghuchu</th><th>Lainya</th>".
                 "<th>A</th><th>B</th><th>AB</th><th>O</th>";
           
            $s .= "</tr></thead><tbody>";
           } else {  
               $s = "<table id=\"report\" align=\"center\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">".
                 "<tr><th rowspan=\"2\">No</th><th rowspan=\"2\">Unit Kerja</th><th rowspan=\"2\">Jumlah</th>".
                 "<th colspan=\"2\">Jenis Kelamin</th>".
                 "<th colspan=\"7\">Agama</th>".
                 "<th colspan=\"4\">Golongan Darah</th></tr>".
                 "<tr> ".
                 "<th>Lk</th><th>Pr</th>".
                 "<th>Islam</th><th>Protestan</th><th>Katolik</th><th>Hindu</th><th>Budha</th><th>Konghuchu</th><th>Lainya</th>".
                 "<th>A</th><th>B</th><th>AB</th><th>O</th>".
                 "</tr>";
            }
            
            return $s;
		}
		
        function list_jumlah_isi($print_mode=false) {
            
            $this->db->from('unit_kerja'); 
            $this->db->where(array('id_kabkota' => KABKOTA));       
            $this->db->order_by('nama asc');
            
            $q = $this->db->get();

            $s = $print_mode?"":"["; 
			$i = 1;
            
			
            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }


                $this->db->select('COUNT(jk) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND jk = "L"');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $jk_l = $r->jm;
                }
                
                $this->db->select('COUNT(jk) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND jk = "P"');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $jk_p = $r->jm;
                } 
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 1');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $islam = $r->jm;
                }
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 2');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $pro = $r->jm;
                }
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 3');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $kat = $r->jm;
                }
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 4');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $bud = $r->jm;
                }
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 5');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $hin = $r->jm;
                }
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 6');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $kong = $r->jm;
                }
                
                $this->db->select('COUNT(id_agama) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND id_agama = 7');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $lain = $r->jm;
                }
                
                $this->db->select('COUNT(goldar) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND goldar = "A"');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $a = $r->jm;
                }
                
                $this->db->select('COUNT(goldar) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND goldar = "B"');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $b = $r->jm;
                }
                
                $this->db->select('COUNT(goldar) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND goldar = "AB"');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $ab = $r->jm;
                }
                
                $this->db->select('COUNT(goldar) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .' AND goldar = "O"');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $o = $r->jm;
                }
                
                $this->db->select('COUNT(goldar) as jm');
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .'');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $jumlah = $r->jm;
                }
                
                if ($print_mode==true)
                    $s .= "<tr><td><div align=\"right\">$i.</div></td>"; 
  
                else
                
                    $s .= "['<tr class=\"$kelas\" id=\"row-".$i."\" ><td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>";
                
                 $s .="<td>".$row->nama."</td><td align=\"center\">$jumlah</td>".
                      "<td>$jk_l</td><td>$jk_p </td>".
                      "<td>$islam</td><td>$pro </td><td>$kat</td><td>$bud</td><td>$hin</td><td>$kong</td><td>$lain</td>".
                      "<td>$a</td><td> $b</td><td> $ab</td><td> $o</td></tr>";
                
                if ($print_mode==false) 
                    $s .= "'],";
                

                $i++;
            }
            
            if ($print_mode==false) 
                $s .= '];';
            else
                $s .= "</tbody></table>";  
            return $s;
        }
        
		
       function pendik_header($print_mode=false) {
           if ($print_mode==false) { 
            $s = "<table id=\"myTable\" class=\"tbl\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" >".
                 "<thead><tr><th rowspan=\"2\">No</th><th rowspan=\"2\">Unit Kerja</th><th rowspan=\"2\">Jumlah</th>".
                 "<th colspan=\"10\">Pendidikan Formal</th>".
                 "<th colspan=\"4\">Diklat Kepeminpinan</th>".
                 "<th rowspan=\"2\">Lemhanas</th></tr>".
                 "<tr> ".
                 "<th>S3</th><th>S2</th><th>S1</th><th>D4</th><th>D3</th><th>D2</th><th>D1</th><th>SLTA</th><th>SLTP</th><th>SD</th>".
                 "<th>Tk.IV</th><th>Tk.III</th><th>Tk.II</th><th>Tk.I</th>".
                 "</tr></thead><tbody>";
            } else {  
               $s = "<table id=\"report\" align=\"center\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">".
                 "<tr><th rowspan=\"2\">No</th><th rowspan=\"2\">Unit Kerja</th><th rowspan=\"2\">Jumlah</th>".
                 "<th colspan=\"10\">Pendidikan Formal</th>".
                 "<th colspan=\"4\">Diklat Kepeminpinan</th>".
                 "<th rowspan=\"2\">Lemhanas</th></tr>".
                 "<tr> ".
                 "<th>S3</th><th>S2</th><th>S1</th><th>D4</th><th>D3</th><th>D2</th><th>D1</th><th>SLTA</th><th>SLTP</th><th>SD</th>".
                 "<th>Tk.IV</th><th>Tk.III</th><th>Tk.II</th><th>Tk.I</th>".
                 "</tr>";;
            }
            $s .= "";
            return $s;
        }
        
        function pendik_isi($print_mode=false) {
            
            
            $this->db->join("unit_kerja", "pegawai.id_unit_kerja=unit_kerja.idspg_unit_kerja");
            $this->db->from('pegawai');
            $this->db->group_by('unit_kerja.nama');
            $this->db->where(array('id_kabkota' => KABKOTA));       
            $this->db->order_by('unit_kerja.nama asc');
            
            $q = $this->db->get();

            $s = $print_mode?"":"["; 
            $i = 1;
            
            
            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
               $id_pend_terakhir = Datum_model::getLatestData('idspg_pendidikan', 'pendidikan', array('id_pegawai' => $row->idspg_pegawai)); 
               $id_diklat_terakhir = Datum_model::getLatestData('idspg_diklat', 'diklat', array('id_pegawai' => $row->idspg_pegawai, 'id_jenis_diklat' => TIPE_DIKLAT_STRUKTURAL));
               $id_jenis_diklat_struktural = Datum_model::getData('id_jenis_diklat_struktural', 'diklat', array('idspg_diklat' => $id_diklat_terakhir));

                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND nama = "S3"');
                //$this->db->group_by('id_pegawai');                                                                     
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $s3 = $r->jt;
      
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND nama = "S2"');                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $s2 = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'"  AND nama = "S1"');                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $s1 = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND nama = "D4"');                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $d4 = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND nama = "D3"');
                                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $d3 = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'"  AND nama = "D2"');
                                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $d2 = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'"  AND nama = "D1"');
                                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $d1 = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND nama = "SLTA"');
                                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $slta = $r->jt;  
                }
                
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'"  AND nama = "SLTP"');
                                                                
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $sltp = $r->jt;  
                }
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND  nama = "SD"');
                                                            
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $sd = $r->jt;  
                }
                
                
                ////
                $this->db->from('diklat');
                $this->db->select('COUNT(id_pegawai) as jt');
                $this->db->join('jenis_diklat_struktural', 'jenis_diklat_struktural.idspg_jenis_diklat_struktural=diklat.id_jenis_diklat_struktural');               
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_diklat = "'.$id_diklat_terakhir.'" AND id_kategori_diklat_struktural = "1"');
    
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $tk_iv = $r->jt;  
                }
                
                
                $this->db->from('diklat');
                $this->db->select('COUNT(id_pegawai) as jt');
                $this->db->join('jenis_diklat_struktural', 'jenis_diklat_struktural.idspg_jenis_diklat_struktural=diklat.id_jenis_diklat_struktural');               
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_diklat = "'.$id_diklat_terakhir.'" AND id_kategori_diklat_struktural = "2"');
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $tk_iii = $r->jt;  
                }
                
                $this->db->from('diklat');
                $this->db->select('COUNT(id_pegawai) as jt');
                $this->db->join('jenis_diklat_struktural', 'jenis_diklat_struktural.idspg_jenis_diklat_struktural=diklat.id_jenis_diklat_struktural');               
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_diklat = "'.$id_diklat_terakhir.'" AND id_kategori_diklat_struktural = "3"');    
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $tk_ii = $r->jt;  
                }
                
                
                
                $this->db->from('diklat');
                $this->db->select('COUNT(id_pegawai) as jt');
                $this->db->join('jenis_diklat_struktural', 'jenis_diklat_struktural.idspg_jenis_diklat_struktural=diklat.id_jenis_diklat_struktural');               
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_diklat = "'.$id_diklat_terakhir.'" AND id_kategori_diklat_struktural = "4"');    
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $tk_i = $r->jt;  
                }
                
                
                
                
                
                $this->db->from('pendidikan');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pendidikan = "'.$id_pend_terakhir.'" AND '.$row->idspg_unit_kerja .' = '.$row->id_unit_kerja .' ');
                //$this->db->group_by('id_pegawai');                                                                     
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $jumlah = $r->jt;
      
                }
                
                 if ($print_mode==true)
                    $s .= "<tr><td><div align=\"right\">$i.</div></td>"; 
  
                else
                 
                    $s .= "['<tr class=\"$kelas\" id=\"row-".$i."\" ><td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>";
                
                $s .="<td>".$row->nama."</td><td align=\"center\">$jumlah</td>".
                      "<td>$s3 </td><td>$s2 </td><td>$s1 </td><td>$d4 </td><td>$d3 </td><td>$d2 </td><td>$d1 </td><td>$slta </td><td>$sltp </td><td>$sd </td>".
                      "<td>$tk_iv </td><td>$tk_iii </td><td>$tk_ii </td><td>$tk_i </td>".
                      "<td></td>";
                
                if ($print_mode==false) 
                    $s .= "'],";

                $i++;
            }
           
             if ($print_mode==false) 
                $s .= '];';
            else
                $s .= "</tbody></table>";  
            return $s;
            
        }
            function gol_header($print_mode=false) {
               if ($print_mode==false) { 
                $s = "<table id=\"myTable\" class=\"tbl\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" >".
                     "<thead><tr><th rowspan=\"3\">No</th><th rowspan=\"3\">Unit Kerja</th><th rowspan=\"3\">Jumlah</th>".                     
                     "<th colspan=\"21\">G o l o n g a n  /  R u a n g</th></tr>".
                     "</tr><th colspan=\"5\">IV</th><th colspan=\"4\">III</th><th colspan=\"4\">II</th><th colspan=\"4\">I</th>".
                     "</tr>".
                     "<tr> ".
                     "<th>e</th><th>d</th><th>c</th><th>b</th><th>a</th>".
                     "<th>d</th><th>c</th><th>b</th><th>a</th>".
                     "<th>d</th><th>c</th><th>b</th><th>a</th>".
                     "<th>d</th><th>c</th><th>b</th><th>a</th>".
                     "</tr></thead><tbody>";
                } else {  
                   $s = "<table id=\"report\" align=\"center\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">".
                     "<tr><th rowspan=\"3\">No</th><th rowspan=\"3\">Unit Kerja</th><th rowspan=\"3\">Jumlah</th>".                     
                     "<th colspan=\"21\">G o l o n g a n  /  R u a n g</th></tr>".
                     "</tr><th colspan=\"5\">IV</th><th colspan=\"4\">III</th><th colspan=\"4\">II</th><th colspan=\"4\">I</th>".
                     "</tr>".
                     "<tr> ".
                     "<th>e</th><th>d</th><th>c</th><th>b</th><th>a</th>".
                     "<th>d</th><th>c</th><th>b</th><th>a</th>".
                     "<th>d</th><th>c</th><th>b</th><th>a</th>".
                     "<th>d</th><th>c</th><th>b</th><th>a</th>".
                     "</tr>";;
                }
                $s .= "";
                return $s;
            }
            
            function gol_isi($print_mode=false) {
            
            
            $this->db->join("unit_kerja", "pegawai.id_unit_kerja=unit_kerja.idspg_unit_kerja");
            $this->db->from('pegawai');
            $this->db->group_by('unit_kerja.nama');
            $this->db->where(array('id_kabkota' => KABKOTA));       
            $this->db->order_by('unit_kerja.nama asc');
            
            $q = $this->db->get();

            $s = $print_mode?"":"["; 
            $i = 1;
           
            
            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
               
                $id_gol_terakhir = Datum_model::getLatestData('idspg_pengangkatan_gol_ruang', 'pengangkatan_gol_ruang', array('id_pegawai' => $row->idspg_pegawai)); 
     
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "17"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iv_e = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "16"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iv_d = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "15"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iv_c = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "14"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iv_b = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "13"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iv_a = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "12"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iii_d = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "11"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iii_c = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "10"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iii_b = $r->jt;     
                }
                
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "9"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $iii_a = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "8"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $ii_d = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "7"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $ii_c = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "6"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $ii_b = $r->jt;     
                }
                
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "5"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $ii_a = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "4"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $i_d = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "18"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $i_c = $r->jt;     
                }
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "3"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $i_b = $r->jt;     
                }
                
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'" AND id_golongan = "2"');                                                                                   
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $i_a = $r->jt;     
                }
                
                
                
                $this->db->from('pengangkatan_gol_ruang');
                $this->db->select('COUNT(id_pegawai) as jt'); 
                $this->db->where('id_pegawai ='.$row->idspg_pegawai.' AND idspg_pengangkatan_gol_ruang = "'.$id_gol_terakhir.'"  ');
                //$this->db->group_by('id_pegawai');                                                                     
                $query = $this->db->get();
                 if ($query->num_rows() > 0) {
                    $r = $query->row(); 
                    $jumlah = $r->jt;
      
                }
                
                if ($print_mode==true)
                    $s .= "<tr><td><div align=\"right\">$i.</div></td>"; 
  
                else
                 
                    $s .= "['<tr class=\"$kelas\" id=\"row-".$i."\" ><td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>";
                 
                $s .= "<td>".$row->nama."</td><td align=\"center\">$jumlah</td>".
                      "<td>$iv_e </td><td>$iv_d </td><td>$iv_c </td><td>$iv_b </td><td>$iv_a </td>".
                      "<td>$iii_d </td><td>$iii_c </td><td>$iii_b </td><td>$iii_a </td>".
                      "<td>$ii_d </td><td>$ii_c </td><td>$ii_b </td><td>$ii_a </td>".
                      "<td>$i_d </td><td>$i_c </td><td>$i_b </td><td>$i_a </td>";
                
                if ($print_mode==false) 
                    $s .= "'],";

                $i++;
            }
             if ($print_mode==false) 
                $s .= '];';
            else
                $s .= "</tbody></table>";  
            return $s;
        }
        
        
        function umur_header($print_mode=false) {
               if ($print_mode==false) { 
                $s = "<table id=\"myTable\" class=\"tbl\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" >".
                     "<thead><tr><th rowspan=\"2\">No</th><th rowspan=\"2\">Unit Kerja</th><th rowspan=\"2\">Jumlah</th>".                     
                     "<th colspan=\"10\">U  s  i  a   ( t a h u n )</th></tr>".
                     "<tr><th>< 20</th><th >21 - 25</th><th>26 - 30</th><th>31 - 35</th><th>36 - 40</th><th>41 - 45</th><th>46 - 50</th><th>51 - 55</th><th>56 - 60</th><th>60 ></th>".                                          
                     "</tr></thead><tbody>";
                } else {  
                   $s = "<table id=\"report\" align=\"center\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">".
                     "<tr><th rowspan=\"2\">No</th><th rowspan=\"2\">Unit Kerja</th><th rowspan=\"2\">Jumlah</th>".                     
                     "<th colspan=\"10\">U  s  i  a   ( t a h u n )</th></tr>".
                     "<tr><th>< 20</th><th >21 - 25</th><th>26 - 30</th><th>31 - 35</th><th>36 - 40</th><th>41 - 45</th><th>46 - 50</th><th>51 - 55</th><th>56 - 60</th><th>60 ></th>". 
                     "</tr>";
                }
                $s .= "";
                return $s;
            }
            
            function umur_isi($print_mode=false) {
            
            $this->db->from('unit_kerja'); 
            $this->db->where(array('id_kabkota' => KABKOTA));       
            $this->db->order_by('nama asc');
            
            $q = $this->db->get();

            $s = $print_mode?"":"["; 
            $i = 1;
            
            
            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }


                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja ='".$row->idspg_unit_kerja ."'");
                $this->db->having("jm < 21");
                $query = $this->db->get('pegawai');
                $dp1 = $query->num_rows(); 

                    
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 21 AND jm < 26");
                $query = $this->db->get('pegawai');
                $dp2 = $query->num_rows(); 

                
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 26 AND jm < 31");
                $query = $this->db->get('pegawai');
                $dp3 = $query->num_rows(); 
              
                
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 31 AND jm < 36");    
                $query = $this->db->get('pegawai');
                $dp4 = $query->num_rows(); 
               
                
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 36 AND jm < 41");
                $query = $this->db->get('pegawai');
                $dp5 = $query->num_rows(); 
                
                
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 41 AND jm < 46");
                $query = $this->db->get('pegawai');
                $dp6 = $query->num_rows(); 
               
                
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 46 AND jm < 51");
                $query = $this->db->get('pegawai');
                $dp7 = $query->num_rows(); 
          
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 51 AND jm < 56");           
                $query = $this->db->get('pegawai');
                $dp8 = $query->num_rows(); 

                
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 56 AND jm < 61");
                $query = $this->db->get('pegawai');
                $dp9 =$query->num_rows(); 
                
                
                $this->db->select("FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm" );
                $this->db->where("id_unit_kerja =".$row->idspg_unit_kerja ."");
                $this->db->having("jm > 61");         
                $query = $this->db->get('pegawai');
                $dp10 = $query->num_rows();

               
                $this->db->select("tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as usia" );  
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .'');
            //    $this->db->having("usia < 61 AND usia > 20");     
                $query = $this->db->get('pegawai');
                $jumlah = $query->num_rows(); 
                
                              
                    
                if ($print_mode==true)
                    $s .= "<tr><td><div align=\"right\">$i.</div></td>"; 
  
                else
                
                    $s .= "['<tr class=\"$kelas\" id=\"row-".$i."\" ><td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>";
                
                 $s .="<td>".$row->nama."</td><td align=\"center\">$jumlah</td>".
                      "<td>$dp1</td><td>$dp2</td><td>$dp3</td><td>$dp4</td><td>$dp5</td><td>$dp6</td><td>$dp7</td><td>$dp8</td><td>$dp9</td><td>$dp10</td>".
                      "</tr>";
                
                if ($print_mode==false) 
                    $s .= "'],";
                

                $i++;
            }
            
            if ($print_mode==false) 
                $s .= '];';
            else
                $s .= "</tbody></table>";  
            return $s;
        }
         
	}
    
    /* $this->db->select('tgl_lahir, FLOOR((TO_DAYS(NOW())- TO_DAYS(tgl_lahir)) / 365.25) as jm' );
                $this->db->where('id_unit_kerja ='.$row->idspg_unit_kerja .'');
                $this->db->having('jm < 21');
                $query = $this->db->get('pegawai');
                if ($query->num_rows() > 0) {
                    $r = $query->row();
                    $dp = count($r->jm);   
                } */
?>

